package 异常;

public class StudentTest {
    public static void main(String[] args) {
        Student student=new Student();
        try {
            student.regist(0);
            System.out.println(student);
        }catch(Exception e){
            System.out.println(e.getMessage());
        }
    }
}
class Student{
    private int id;
    public void regist (int id)throws Exception{
        if(id>0){
            this.id=id;
        }else{
           // System.out.println("输入数据非法");
            //手动的抛出异常
            throw new Exception("输入数据非法");
        }
    }
    @Override
    public String toString(){
        return getClass()+"id="+id;
    }
}
